#
# @lc app=leetcode.cn id=232 lang=python3
#
# [232] 用栈实现队列
#

# @lc code=start
class MyQueue:
    # 使用双栈实现队列
    def __init__(self):
        """
        Initialize your data structure here.
        """
        self.stk1 = []
        self.stk2 = []

    def push(self, x: int) -> None:
        """
        Push element x to the back of queue.
        """
        # 两个栈倒，新来的元素总是在栈底（队尾进）
        if self.stk1 == None:
            self.stk1.append(x)
        else:
            while self.stk1:
                self.stk2.append(self.stk1.pop(-1))
            self.stk1.append(x)
            while self.stk2:
                self.stk1.append(self.stk2.pop(-1))

    def pop(self) -> int:
        """
        Removes the element from in front of queue and returns that element.
        """
        return self.stk1.pop()

    def peek(self) -> int:
        """
        Get the front element.
        """
        if self.stk1:
            return self.stk1[-1]
        
    def empty(self) -> bool:
        """
        Returns whether the queue is empty.
        """
        # 队列１存储了所有元素
        return len(self.stk1) == 0

    

# Your MyQueue object will be instantiated and called as such:
# obj = MyQueue()
# obj.push(x)
# param_2 = obj.pop()
# param_3 = obj.peek()
# param_4 = obj.empty()
# @lc code=end

